package com.gitee.zycra.union.api.common.param;

import com.gitee.zycra.union.api.common.model.ApiMockInstanceCase;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zycra
 */
@Getter
@Setter
@ToString
@Accessors(chain = true)
public class AddMockInstanceParam {

    /**
     * 模板ID
     */
    @NotNull(message = "模板ID不能为空")
    private Long templateId;

    /**
     * 实例名称
     */
    @NotNull(message = "实例名称不能为空")
    private String instanceName;

    /**
     * 期望配置
     */
    @NotEmpty(message = "期望配置不能为空")
    @Valid
    private List<AddMockInstanceSubParam> caseList;

    public static List<ApiMockInstanceCase> convertToApiMockInstanceCaseList(List<AddMockInstanceSubParam> addMockInstanceSubParamList,
                                                                             Long instanceId) {
        if (addMockInstanceSubParamList == null || addMockInstanceSubParamList.isEmpty()) {
            return new ArrayList<>();
        }
        List<ApiMockInstanceCase> result = new ArrayList<>(addMockInstanceSubParamList.size());
        for (AddMockInstanceSubParam mockInstanceSubParam : addMockInstanceSubParamList) {
            result.add(new ApiMockInstanceCase().setInterfaceId(mockInstanceSubParam.getInterfaceId())
                    .setCaseId(mockInstanceSubParam.getCaseId()).setInstanceId(instanceId));
        }
        return result;
    }
}
